<?php
/**
 * 简单Mysql数据库操作封装
 */
function DB_Connection($host , $user , $pass , $db , $charset = 'utf-8'){	
	$conn = @mysql_connect($host, $user, $pass);
	if (empty($conn)) {
		exit(message('数据库连接错误！'));
		return null;
	}
	mysql_select_db($db, $conn);
	mysql_query("set names ".$charset);
	return $conn;
}

function DB_Query($sql){
    return mysql_query($sql);  
}

function DB_Rows($sql){
	$rs = DB_Query($sql);
	return mysql_numrows($rs);
}

function DB_getRow($rs){
	return mysql_numrows($rs);
}

function DB_Result($sql){
	$rs = DB_Query($sql);
	if (empty($rs)) {
		return null;
	}
	if(mysql_numrows($rs) > 0){
		return mysql_result($rs , 0);
	}
	return 0;
}

function DB_getResult($rs){
	return mysql_result($rs , 0);
}

function DB_ResultSet($sql){
	$rs = DB_Query($sql);
	if (empty($rs)) {
	 return null;
	}

	$list = array();
	while ($row = mysql_fetch_array($rs)) {
	  $list[] = $row;
	}

	return  $list;
}

function DB_Set($rs){
	if($rs != null){
	    return mysql_fetch_array($rs);	
	}
	return null;
}

function DB_QuerySet($sql){
	$rs = DB_Query($sql);
	return mysql_fetch_array($rs);
}

function DB_InserId(){
	return mysql_insert_id();
}

function DB_getError(){
	return mysql_error();
}

?>